package com.acme.bankapp.service;

import com.acme.bankapp.domain.Bank;
import com.acme.bankapp.domain.Client;

/**
 *
 * Aggregates delegate methods that perform financial operations over bank's clients' accounts.
 * Holds reference to the Bank object.
 *
 */
public class AccountService {
	Bank bank;

	/**
	 * Constructs Service with specified Bank.
	 * @param bank
	 */
	public AccountService(Bank bank){
		this.bank = bank;
	}

	/**
	 * Adds amount to client's account.
	 * @param client
	 * @param amount
	 */
	public boolean deposit(Client client, double amount) {
		return client.getAccount().deposit(amount);
	}	  

	/**
	 * Withdraws amount from client's account if possible.
	 * @param client
	 * @param amount
	 * @return true if possible to withdraw, false otherwise.
	 */
	public boolean withdraw(Client client, double amount) {
		return client.getAccount().withdraw(amount);
	}

	/**
	 * Adds amount to account specified by client's name.
	 * @param clientName
	 * @param amount
	 */
	public boolean deposit(String clientName, double amount) {
		return bank.getClientByName(clientName).getAccount().deposit(amount);
	}

	/**
	 * Withdraws amount if possible from account specified by client's name.
	 * @param clientName
	 * @param amount
	 */
	public boolean withdraw(String clientName, double amount) {
		return bank.getClientByName(clientName).getAccount().withdraw(amount);
	}
}
